# -*- coding: utf-8 -*-

# File Name： base_trainer
# Description :
# Author : lirui
# create_date： 2022/6/3
# Change Activity:
"""
Base class of model training.
"""
from abc import ABC, abstractmethod


class BaseTrainer(ABC):

    def __init__(self, train_cfg, model):
        """


        Args:
            train_cfg: training config, including pipline and other parameters.
            model: torch model.
        """
        self.train_cfg = train_cfg
        self.model = self._load_model(model)

    def _load_model(self, model):
        """
        build model.
        Args:
            model:

        Returns:

        """
        if not isinstance(model, dict):
            return model
        return self._build_model_from_cfg(model)

    @staticmethod
    @abstractmethod
    def _build_model_from_cfg(model_cfg):
        pass

    @abstractmethod
    def train(self):
        """
        Train a model.


        """
        pass

    @abstractmethod
    def before_train_one_epoch(self):
        pass

    @abstractmethod
    def after_train_one_epoch(self):
        pass

    @abstractmethod
    def train_one_epoch(self):
        pass

    @abstractmethod
    def before_train_one_batch(self):
        pass

    @abstractmethod
    def after_train_one_batch(self):
        pass

    @abstractmethod
    def train_one_batch(self, batch):
        pass
